package com.itheima.day16反射机制与类加载.反射核心案例_使用场景;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Properties;

public class 类加载加反射机制案例一 {
    public static void main(String[] args) throws Exception {
        ClassLoader loader = ClassLoader.getSystemClassLoader();
        InputStream resourceAsStream = loader.getResourceAsStream("prop.properties");
        BufferedReader br = new BufferedReader(new InputStreamReader(resourceAsStream));
        Properties prop = new Properties();
        prop.load(br);
        Class clazz = Class.forName(prop.getProperty("className"));
        Constructor con = clazz.getDeclaredConstructor();
        con.setAccessible(true);
        Object obj = con.newInstance();
        Method method = clazz.getDeclaredMethod(prop.getProperty("method"));
        method.setAccessible(true);
        Object invoke = method.invoke(obj);
        if (invoke != null) {
            System.out.println(invoke);
        }
    }
}
